﻿
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Red.Core
{
    /// <summary>
    /// Base class for view models, implementing INotifyPropertyChanged
    /// </summary>
    public abstract class ViewModel : INotifyPropertyChanged, INotifyPropertyChanging
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public event PropertyChangingEventHandler PropertyChanging;

        protected virtual void OnPropertyChanged( [CallerMemberName] string propertyName = null )
        {
            if ( PropertyChanged != null ) 
            {
                PropertyChanged( this, new PropertyChangedEventArgs( propertyName ) );
            }
        }

        protected virtual void OnPropertyChanging( [CallerMemberName] string propertyName = null )
        {
            if ( PropertyChanging != null )
            {
                PropertyChanging( this, new PropertyChangingEventArgs( propertyName ) );
            }
        }
    }
}
